package com.aaa.controller;

import com.aaa.entity.Staff;
import com.aaa.service.OrderdetailsService;
import com.aaa.service.RoomService;
import com.aaa.service.impl.RoomServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RequestMapping("room")
@RestController
public class RoomController {
    @Resource
    private RoomService roomService;
    @Resource
    private OrderdetailsService orderdetailsService;
    @RequestMapping("findroom")
    public List<Map<String,Object>> findroom(String startdate,String enddate,Integer rtid){
        return roomService.findroom(startdate,enddate,rtid);
    }
    @RequestMapping("roomload")
    public Object roomload(Integer rtid, Integer pageNum, Integer pageSize,String state) throws ParseException {

        return roomService.roomload(rtid,state,pageNum,pageSize);
    }
    @RequestMapping("findroombyid")
    public List<Map<String,Object>> findroombyid(Integer id){
        return orderdetailsService.findroombyid(id);
    }
    @RequestMapping("checkout")
    public Object checkout(Integer rid) throws ParseException {
        return roomService.checkout(rid);
    }
    @RequestMapping("findchangeroom")
    public List<Map<String,Object>> findchangeroom(Integer rid,Integer odid,String enddate){
        return roomService.findchangeroom(rid,odid,enddate);
    }
    @RequestMapping("checkroom")
    public List<Map<String,Object>> checkroom(String rname){
        return roomService.checkroom(rname);
    }
    @RequestMapping("findcheckroom")
    public List<Map<String,Object>> findcheckroom(String oldrname,String rname){
        List<Map<String,Object>> list=roomService.checkroom(rname);
        if(list.size()>0&&list!=null){
            if(list.get(0).get("rname").equals(oldrname)){
                list.remove(0);
            }
        }
        return list;
    }
    @RequestMapping("changeroom")
    public Object changeroom(Authentication authentication,Integer newrid, Integer odid, double money, Integer oldrid) throws ParseException {
        Integer staff = ((Staff) authentication.getPrincipal()).getId();
        return roomService.changeroom(newrid,odid,money,oldrid,staff);
    }
    @RequestMapping("addroom")
    public Integer addroom(String rname,Integer tid){
        System.out.println("__________________"+tid);
        String state="可入住";
        return roomService.addroom(rname,tid,state);
    }
    @RequestMapping("findReadyRoom")
    public List<Map<String ,Object>> findReadyRoom(String enddate){
        return roomService.findReadyRoom(enddate);
    }
    @RequestMapping("changeRoomMoney")
    public Object changeRoomMoney(Integer oldrid,Integer newrid,String enddate) throws ParseException {
        return roomService.changeRoomMoney(oldrid,newrid,enddate);
    }
}
